<template>
	<view class="pages">
		<view class="search_warp u-flex-x-center">
			<view class="search u-flex-y-center u-flex-between">
				<view class="u-flex-y-center">
					<view class="search_img">
						<image :src="`${$http_cos}/static/search.png`"></image>
					</view>
					<input type="number" v-model="num_id" placeholder="输入编号"  @keyup.enter.native="$event.target.blur()" @blur="onSearch"/>
				</view>
				<view class="search_btn" @keyup.enter.native="onSearch">
					<text>搜索</text>
				</view>
			</view>
			<view class="u-flex-x-center screening_warp" @click="skip('/pages/conditional_screening/index')">
				<view class="screen">
					<image src="https://hl-1316403513.cos.ap-shanghai.myqcloud.com/static/%E7%AD%9B%E9%80%89.png">
					</image>
				</view>
				<text>筛选</text>
			</view>
		</view>
		<view class="main">
			<view class="item u-flex-between u-flex" v-for="(item,index) in proData" :key="index" @click="skip_details(item)">
				<view class="avatar">
					<u--image :src="get_src(item.matchmakerMeitu)" height="232" width="184" >
					</u--image>
					<!-- :lazy-load="true" :fade="true"
					duration="450" -->
					<!-- <u-lazy-load :image="get_src(item.matchmakerMeitu)"></u-lazy-load> -->
					<!-- <image :src="get_src(item.matchmakerMeitu)" mode="aspectFill"></image> -->
				</view>
				<view class="u-flex-1">
					<view class="u-flex u-flex-between item_top">
						<view class="u-flex-y-center">
							<text>{{item.userId}}</text>
							<view class="sex">
								<image :src="`${$http_cos}${item.sex=='男'?'/static/boy':'/static/%E5%A5%B3'}.png`" mode="heightFix"></image>
							</view>
						</view>
						<text class="descriptiveDescription">{{item.descriptiveDescription}}</text>
					</view>
					<view class="info_introduce">
						<text>
							{{item.title}}
						</text>
					</view>
				</view>
			</view>
			<u-empty
			v-if="proData.length==0"
			textSize='30'
			        mode="data"
					width="200"
					height="200"
					icon="https://hl-1316403513.cos.ap-shanghai.myqcloud.com/static/%E6%95%B0%E6%8D%AE%E4%B8%BA%E7%A9%BA.png"
			>
			</u-empty>
		</view>
	</view>
</template>

<script>
	import {
		getSinglesSquare,
		getUserInfo
	} from '@/common/api.js'
	const app = getApp();
	export default {
		data() {
			return {
				$http_cos:app.$http_cos,
				proData:[],
				num_id:'',
				isRefresh:true,
				formData: {
					religion:'',//宗教
					id: 0 , //编号搜索
					sex:'不限', //性别搜索 男 or 女
					minHeight: 140, //年龄搜索 最小年龄
					maxHeight: 229, //年龄搜索 最大年龄
					minAge: 18, //身高搜索 最小搜索
					maxAge: 50, //身高搜索 最大搜索
					maritalStatus:'', //婚姻状况 多个逗号隔开
					education: '', //学历
					jgArea: '', //籍贯区 
					nhArea: '', //现居区
					occupation: '', //职业性质 正式工 or 非正式工
					carPurchase: '', //购车情况车俩情况
					housingSituation: '', //住房情况房产情况
					canSmoke: '', //爱抽烟情况 多个逗号隔开
					likeDrink: '', //爱喝酒情况 多个逗号隔开
					page: 1,
					perPage: 10,
					count:0
				}
			}
		},
		onLoad() {

		},
		watch:{
			num_id(val){
				this.formData.id=Number(val)
			}
		},
		onShow() {
			// alert('1')
			
			this.get_SinglesSquare()
			setTimeout(()=>{
				this.isRefresh=true
			},700)
		},
		onReachBottom() {
			// alert('下啦')
			if(this.isRefresh==false)return
			this.get_SinglesSquare()
			
		},
		onPullDownRefresh(){
			// setTimeout(()=>{
			// 				this.onSearch()
			// 				uni.stopPullDownRefresh();//关闭刷新状态
			// 			},2000);	
		},
		methods: {
			get_UserInfo() {
				return new Promise(resolve => {
							getUserInfo({
									custom: {
										auth: false,
										toast: false,
										catch: false
									}
								}).then((result) => {
									resolve(result)
									// this.user_info = r
							}).catch((err) => {
										reject(err)
							})
				})
			},
			skip_details(item){
					uni.navigateTo({
						url:'/pagesA/square_details/index'+'?id='+item.userId
					})
			},
			onSearch(){
				
				this.formData.page=1
				this.formData.count=0
				this.proData=[]
				setTimeout(()=>{
					this.get_SinglesSquare()
				},300)
			},
			get_src(it){
				let {url}=JSON.parse(it)[0]
				return url+'?imageView2/2/w/750/h/q/85'
			},	
			async skip(url) {
				try {
					if (uni.getStorageSync('access_token')) {
						let user_info= await this.get_UserInfo()
						if(user_info.memberId>0||user_info.isMatchmaker ===1 ){
							uni.navigateTo({
								url: url+'?formData='+JSON.stringify(this.formData)
							})
						}else{
							uni.$u.toast('请“我的-联系红娘”成为线下门店会员才能使用此功能！')
						}
					} else {
						uni.navigateTo({
							url: '/pages/guide/index'
						})
					}		
				} catch (e) {
					//TODO handle the exception
				}
				
			},
			get_SinglesSquare() {
				let data = {
					params: this.formData
				}
				getSinglesSquare(data, {
					custom: {
						auth: false,
						toast: false,
						catch: false
					}
				}).then((result) => {
					this.proData = [...this.proData, ...result.list]
					this.formData.count=result.count
					// result.list.length <= 0 ? this.status = 'noMore' : this.status = 'more'
					this.formData.page++;
				}).catch((err) => {

				})

			}
		}
	}
</script>

<style lang="scss">
	.pages {
		/deep/ .z-paging-content{
			margin-top:96rpx;
		}
		.search_warp {
			padding: 12rpx 24rpx;
			box-sizing: border-box;
			background-color: #fff;
			height: 96rpx;
			position: fixed;
			left:0;
			top:0;
			right:0;
			z-index: 2222;
			.screening_warp {
				padding: 0 14rpx 0 40rpx;
				align-items: center;

				.screen {
					width: 28rpx;
					height: 28rpx;
					margin-right: 14rpx;
					// padding:0 40rpx;
				}

				text {
					width: auto;
					font-size: 28rpx;
					white-space: nowrap;
					color: #000000;
				}
			}

			.search {
				position: relative;
				height: 72rpx;
				width: 100%;
				background: #F9F9F9;
				border-radius: 36rpx;
				padding: 0 30rpx 0 32rpx;
				box-sizing: border-box;

				.search_img {
					width: 36rpx;
					height: 36rpx;
					margin-right: 8rpx;
				}

				input {
					font-size: 28rpx;
					color: #C9C9C9;
				}

				.search_btn {
					padding: 0 24rpx;
					box-sizing: border-box;
					position: relative;

					&::after {
						content: '';
						position: absolute;
						left: 0;
						top: 0;
						width: 2rpx;
						height: 100%;
						background: #E5E5E5;
						-webkit-transform: scaleX(.5);
						transform: scaleX(.5);
					}

					text {
						font-size: 28rpx;
						font-weight: 400;
						color: #111111;
					}
				}
			}
		}

		.main {
			padding: 20rpx 24rpx;
			box-sizing: border-box;
			margin-top:96rpx;
			.item {
				&:last-child {
					margin-bottom: 0rpx;
				}

				padding:24rpx 20rpx;
				background-color: #fff;
				border-radius:10rpx;
				margin-bottom:24rpx;

				.avatar {
					width: 184rpx;
					height: 232rpx;
					border-radius: 10rpx;
					overflow: hidden;
					margin-right: 24rpx;
					// /deep/.u-image{
					// 	width: 100% !important;
					// 	height:100% !important;
					// }
					// background-color:red;
				}

				.item_top {
					padding: 9rpx 5rpx 9rpx 0;
					box-sizing: border-box;
					align-items: center;
					.descriptiveDescription{
						width:270rpx;
						font-size: 28rpx;
						font-weight: 400;
						text-align: right;
						color: #111111;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 1;
						letter-spacing: 30;
						
					}
					text {
						font-weight: 400;

						&:first-child {
							font-size: 34rpx;
							;
							color: #000000;
						}

						&:last-child {
							color: #FF7612;
							font-size: 28rpx;
						}
					}

					.sex {
						width: auto;
						height: 28rpx;
						margin-left: 8rpx;
					}
				}

				.info_introduce {
					text {
						line-height: 42rpx;
						font-size: 28rpx;
						font-weight: 400;
						color: #111111;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 4;
						letter-spacing: 30;
					}
				}

			}
		}

	}
</style>
